using System.ComponentModel.DataAnnotations.Schema;
using System.Data.Entity.ModelConfiguration;using Maxleaf.EDI.Domain.K3;

namespace Maxleaf.EDI.DataAccess.K3
{
    public class UserPortalMap : EntityTypeConfiguration<UserPortal>
    {
        public UserPortalMap()
        {
            // Primary Key
            this.HasKey(t => new { t.UserId, t.PortalId });

            // Properties
            this.Property(t => t.UserId)
                .HasDatabaseGeneratedOption(DatabaseGeneratedOption.None);

            this.Property(t => t.PortalId)
                .HasDatabaseGeneratedOption(DatabaseGeneratedOption.None);

            this.Property(t => t.UserPortalId)
                .HasDatabaseGeneratedOption(DatabaseGeneratedOption.Identity);

            // Table & Column Mappings
            this.ToTable("UserPortals");
            this.Property(t => t.UserId).HasColumnName("UserId");
            this.Property(t => t.PortalId).HasColumnName("PortalId");
            this.Property(t => t.UserPortalId).HasColumnName("UserPortalId");
            this.Property(t => t.CreatedDate).HasColumnName("CreatedDate");
            this.Property(t => t.Authorised).HasColumnName("Authorised");

            // Relationships
            this.HasRequired(t => t.Portal)
                .WithMany(t => t.UserPortals)
                .HasForeignKey(d => d.PortalId);
            this.HasRequired(t => t.User)
                .WithMany(t => t.UserPortals)
                .HasForeignKey(d => d.UserId);

        }
    }
}
